package com.zxs.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zxs.infra.basic.entity.SubjectBrief;
import com.zxs.infra.basic.entity.SubjectJudge;
import com.zxs.infra.basic.mapper.SubjectBriefMapper;
import com.zxs.infra.basic.service.SubjectBriefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 简答题表(SubjectBrief)表服务实现类
 *
 * @author makejava
 * @since 2025-11-12 21:02:56
 */
@Service
public class SubjectBriefServiceImpl implements SubjectBriefService {
    @Autowired
    private SubjectBriefMapper subjectBriefMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectBrief queryById(Integer id) {
        return this.subjectBriefMapper.queryById(id);
    }



    /**
     * 新增数据
     *
     * @param subjectBrief 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectBrief insert(SubjectBrief subjectBrief) {
        this.subjectBriefMapper.insert(subjectBrief);
        return subjectBrief;
    }

    /**
     * 修改数据
     *
     * @param subjectBrief 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectBrief update(SubjectBrief subjectBrief) {
        this.subjectBriefMapper.update(subjectBrief);
        return this.queryById(subjectBrief.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.subjectBriefMapper.deleteById(id) > 0;
    }

    @Override
    public Integer batchInsert(List<SubjectBrief> subjectBriefs) {
        return subjectBriefMapper.insertBatch(subjectBriefs);
    }

    @Override
    public SubjectBrief queryBySubjectId(int subjectId) {
        LambdaQueryWrapper<SubjectBrief> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SubjectBrief::getSubjectId, subjectId);
        SubjectBrief subjectBrief = subjectBriefMapper.selectOne(queryWrapper);
        return subjectBrief;
    }
}
